<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件绑定指令 </title>
</head>
<style>
    .container {
        width: 400px;
        margin: 0 auto;
        text-align: center;
    }

    .square {
        width: 200px;
        height: 200px;
        background-color: red;
        margin: 0 auto;
    }
</style>

<body>
    <div id="app" class="container">
        <div class="square" v-show="show"></div>
        <br />
        <button @click="toggle()">点击切换</button>
        <!-- <button v-on:click="toggle()">点击切换</button> -->
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script>
        const app = new Vue({
            el: "#app",
            data: {
                show: true
            },
            // 事件函数需定义在 methods 中 
            methods: {
                // ES6 对象函数的简写方式 
                toggle() {
                    this.show = !this.show;
                }
            }
        });
    </script>
</body>

</html>